#!/usr/bin/env python
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements.  See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership.  The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License.  You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

#!/usr/bin/env python
#
# Autogenerated by Thrift Compiler (0.19.0)
#
# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
#
#  options string: py:utf8strings
#

import sys
import pprint
if sys.version_info[0] > 2:
    from urllib.parse import urlparse
else:
    from urlparse import urlparse
from thrift.transport import TTransport, TSocket, TSSLSocket, THttpClient
from thrift.protocol.TBinaryProtocol import TBinaryProtocol

from storm import Nimbus
from storm.ttypes import *

if len(sys.argv) <= 1 or sys.argv[1] == '--help':
    print('')
    print('Usage: ' + sys.argv[0] + ' [-h host[:port]] [-u url] [-f[ramed]] [-s[sl]] [-novalidate] [-ca_certs certs] [-keyfile keyfile] [-certfile certfile] function [arg1 [arg2...]]')
    print('')
    print('Functions:')
    print('  void submitTopology(string name, string uploadedJarLocation, string jsonConf, StormTopology topology)')
    print('  void submitTopologyWithOpts(string name, string uploadedJarLocation, string jsonConf, StormTopology topology, SubmitOptions options)')
    print('  void killTopology(string name)')
    print('  void killTopologyWithOpts(string name, KillOptions options)')
    print('  void activate(string name)')
    print('  void deactivate(string name)')
    print('  void rebalance(string name, RebalanceOptions options)')
    print('  void setLogConfig(string name, LogConfig config)')
    print('  LogConfig getLogConfig(string name)')
    print('  void debug(string name, string component, bool enable, double samplingPercentage)')
    print('  void setWorkerProfiler(string id, ProfileRequest profileRequest)')
    print('   getComponentPendingProfileActions(string id, string component_id, ProfileAction action)')
    print('  void uploadNewCredentials(string name, Credentials creds)')
    print('  string beginCreateBlob(string key, SettableBlobMeta meta)')
    print('  string beginUpdateBlob(string key)')
    print('  void uploadBlobChunk(string session, string chunk)')
    print('  void finishBlobUpload(string session)')
    print('  void cancelBlobUpload(string session)')
    print('  ReadableBlobMeta getBlobMeta(string key)')
    print('  void setBlobMeta(string key, SettableBlobMeta meta)')
    print('  BeginDownloadResult beginBlobDownload(string key)')
    print('  string downloadBlobChunk(string session)')
    print('  void deleteBlob(string key)')
    print('  ListBlobsResult listBlobs(string session)')
    print('  i32 getBlobReplication(string key)')
    print('  i32 updateBlobReplication(string key, i32 replication)')
    print('  void createStateInZookeeper(string key)')
    print('  string beginFileUpload()')
    print('  void uploadChunk(string location, string chunk)')
    print('  void finishFileUpload(string location)')
    print('  string downloadChunk(string id)')
    print('  string getNimbusConf()')
    print('  ClusterSummary getClusterInfo()')
    print('   getTopologySummaries()')
    print('  TopologySummary getTopologySummaryByName(string name)')
    print('  TopologySummary getTopologySummary(string id)')
    print('  NimbusSummary getLeader()')
    print('  bool isTopologyNameAllowed(string name)')
    print('  TopologyInfo getTopologyInfoByName(string name)')
    print('  TopologyInfo getTopologyInfo(string id)')
    print('  TopologyInfo getTopologyInfoByNameWithOpts(string name, GetInfoOptions options)')
    print('  TopologyInfo getTopologyInfoWithOpts(string id, GetInfoOptions options)')
    print('  TopologyPageInfo getTopologyPageInfo(string id, string window, bool is_include_sys)')
    print('  SupervisorPageInfo getSupervisorPageInfo(string id, string host, bool is_include_sys)')
    print('  ComponentPageInfo getComponentPageInfo(string topology_id, string component_id, string window, bool is_include_sys)')
    print('  string getTopologyConf(string id)')
    print('  StormTopology getTopology(string id)')
    print('  StormTopology getUserTopology(string id)')
    print('  TopologyHistoryInfo getTopologyHistory(string user)')
    print('   getOwnerResourceSummaries(string owner)')
    print('  SupervisorAssignments getSupervisorAssignments(string node)')
    print('  void sendSupervisorWorkerHeartbeats(SupervisorWorkerHeartbeats heartbeats)')
    print('  void sendSupervisorWorkerHeartbeat(SupervisorWorkerHeartbeat heatbeat)')
    print('  void processWorkerMetrics(WorkerMetrics metrics)')
    print('  bool isRemoteBlobExists(string blobKey)')
    print('')
    sys.exit(0)

pp = pprint.PrettyPrinter(indent=2)
host = 'localhost'
port = 9090
uri = ''
framed = False
ssl = False
validate = True
ca_certs = None
keyfile = None
certfile = None
http = False
argi = 1

if sys.argv[argi] == '-h':
    parts = sys.argv[argi + 1].split(':')
    host = parts[0]
    if len(parts) > 1:
        port = int(parts[1])
    argi += 2

if sys.argv[argi] == '-u':
    url = urlparse(sys.argv[argi + 1])
    parts = url[1].split(':')
    host = parts[0]
    if len(parts) > 1:
        port = int(parts[1])
    else:
        port = 80
    uri = url[2]
    if url[4]:
        uri += '?%s' % url[4]
    http = True
    argi += 2

if sys.argv[argi] == '-f' or sys.argv[argi] == '-framed':
    framed = True
    argi += 1

if sys.argv[argi] == '-s' or sys.argv[argi] == '-ssl':
    ssl = True
    argi += 1

if sys.argv[argi] == '-novalidate':
    validate = False
    argi += 1

if sys.argv[argi] == '-ca_certs':
    ca_certs = sys.argv[argi+1]
    argi += 2

if sys.argv[argi] == '-keyfile':
    keyfile = sys.argv[argi+1]
    argi += 2

if sys.argv[argi] == '-certfile':
    certfile = sys.argv[argi+1]
    argi += 2

cmd = sys.argv[argi]
args = sys.argv[argi + 1:]

if http:
    transport = THttpClient.THttpClient(host, port, uri)
else:
    if ssl:
        socket = TSSLSocket.TSSLSocket(host, port, validate=validate, ca_certs=ca_certs, keyfile=keyfile, certfile=certfile)
    else:
        socket = TSocket.TSocket(host, port)
    if framed:
        transport = TTransport.TFramedTransport(socket)
    else:
        transport = TTransport.TBufferedTransport(socket)
protocol = TBinaryProtocol(transport)
client = Nimbus.Client(protocol)
transport.open()

if cmd == 'submitTopology':
    if len(args) != 4:
        print('submitTopology requires 4 args')
        sys.exit(1)
    pp.pprint(client.submitTopology(args[0], args[1], args[2], eval(args[3]),))

elif cmd == 'submitTopologyWithOpts':
    if len(args) != 5:
        print('submitTopologyWithOpts requires 5 args')
        sys.exit(1)
    pp.pprint(client.submitTopologyWithOpts(args[0], args[1], args[2], eval(args[3]), eval(args[4]),))

elif cmd == 'killTopology':
    if len(args) != 1:
        print('killTopology requires 1 args')
        sys.exit(1)
    pp.pprint(client.killTopology(args[0],))

elif cmd == 'killTopologyWithOpts':
    if len(args) != 2:
        print('killTopologyWithOpts requires 2 args')
        sys.exit(1)
    pp.pprint(client.killTopologyWithOpts(args[0], eval(args[1]),))

elif cmd == 'activate':
    if len(args) != 1:
        print('activate requires 1 args')
        sys.exit(1)
    pp.pprint(client.activate(args[0],))

elif cmd == 'deactivate':
    if len(args) != 1:
        print('deactivate requires 1 args')
        sys.exit(1)
    pp.pprint(client.deactivate(args[0],))

elif cmd == 'rebalance':
    if len(args) != 2:
        print('rebalance requires 2 args')
        sys.exit(1)
    pp.pprint(client.rebalance(args[0], eval(args[1]),))

elif cmd == 'setLogConfig':
    if len(args) != 2:
        print('setLogConfig requires 2 args')
        sys.exit(1)
    pp.pprint(client.setLogConfig(args[0], eval(args[1]),))

elif cmd == 'getLogConfig':
    if len(args) != 1:
        print('getLogConfig requires 1 args')
        sys.exit(1)
    pp.pprint(client.getLogConfig(args[0],))

elif cmd == 'debug':
    if len(args) != 4:
        print('debug requires 4 args')
        sys.exit(1)
    pp.pprint(client.debug(args[0], args[1], eval(args[2]), eval(args[3]),))

elif cmd == 'setWorkerProfiler':
    if len(args) != 2:
        print('setWorkerProfiler requires 2 args')
        sys.exit(1)
    pp.pprint(client.setWorkerProfiler(args[0], eval(args[1]),))

elif cmd == 'getComponentPendingProfileActions':
    if len(args) != 3:
        print('getComponentPendingProfileActions requires 3 args')
        sys.exit(1)
    pp.pprint(client.getComponentPendingProfileActions(args[0], args[1], eval(args[2]),))

elif cmd == 'uploadNewCredentials':
    if len(args) != 2:
        print('uploadNewCredentials requires 2 args')
        sys.exit(1)
    pp.pprint(client.uploadNewCredentials(args[0], eval(args[1]),))

elif cmd == 'beginCreateBlob':
    if len(args) != 2:
        print('beginCreateBlob requires 2 args')
        sys.exit(1)
    pp.pprint(client.beginCreateBlob(args[0], eval(args[1]),))

elif cmd == 'beginUpdateBlob':
    if len(args) != 1:
        print('beginUpdateBlob requires 1 args')
        sys.exit(1)
    pp.pprint(client.beginUpdateBlob(args[0],))

elif cmd == 'uploadBlobChunk':
    if len(args) != 2:
        print('uploadBlobChunk requires 2 args')
        sys.exit(1)
    pp.pprint(client.uploadBlobChunk(args[0], args[1],))

elif cmd == 'finishBlobUpload':
    if len(args) != 1:
        print('finishBlobUpload requires 1 args')
        sys.exit(1)
    pp.pprint(client.finishBlobUpload(args[0],))

elif cmd == 'cancelBlobUpload':
    if len(args) != 1:
        print('cancelBlobUpload requires 1 args')
        sys.exit(1)
    pp.pprint(client.cancelBlobUpload(args[0],))

elif cmd == 'getBlobMeta':
    if len(args) != 1:
        print('getBlobMeta requires 1 args')
        sys.exit(1)
    pp.pprint(client.getBlobMeta(args[0],))

elif cmd == 'setBlobMeta':
    if len(args) != 2:
        print('setBlobMeta requires 2 args')
        sys.exit(1)
    pp.pprint(client.setBlobMeta(args[0], eval(args[1]),))

elif cmd == 'beginBlobDownload':
    if len(args) != 1:
        print('beginBlobDownload requires 1 args')
        sys.exit(1)
    pp.pprint(client.beginBlobDownload(args[0],))

elif cmd == 'downloadBlobChunk':
    if len(args) != 1:
        print('downloadBlobChunk requires 1 args')
        sys.exit(1)
    pp.pprint(client.downloadBlobChunk(args[0],))

elif cmd == 'deleteBlob':
    if len(args) != 1:
        print('deleteBlob requires 1 args')
        sys.exit(1)
    pp.pprint(client.deleteBlob(args[0],))

elif cmd == 'listBlobs':
    if len(args) != 1:
        print('listBlobs requires 1 args')
        sys.exit(1)
    pp.pprint(client.listBlobs(args[0],))

elif cmd == 'getBlobReplication':
    if len(args) != 1:
        print('getBlobReplication requires 1 args')
        sys.exit(1)
    pp.pprint(client.getBlobReplication(args[0],))

elif cmd == 'updateBlobReplication':
    if len(args) != 2:
        print('updateBlobReplication requires 2 args')
        sys.exit(1)
    pp.pprint(client.updateBlobReplication(args[0], eval(args[1]),))

elif cmd == 'createStateInZookeeper':
    if len(args) != 1:
        print('createStateInZookeeper requires 1 args')
        sys.exit(1)
    pp.pprint(client.createStateInZookeeper(args[0],))

elif cmd == 'beginFileUpload':
    if len(args) != 0:
        print('beginFileUpload requires 0 args')
        sys.exit(1)
    pp.pprint(client.beginFileUpload())

elif cmd == 'uploadChunk':
    if len(args) != 2:
        print('uploadChunk requires 2 args')
        sys.exit(1)
    pp.pprint(client.uploadChunk(args[0], args[1],))

elif cmd == 'finishFileUpload':
    if len(args) != 1:
        print('finishFileUpload requires 1 args')
        sys.exit(1)
    pp.pprint(client.finishFileUpload(args[0],))

elif cmd == 'downloadChunk':
    if len(args) != 1:
        print('downloadChunk requires 1 args')
        sys.exit(1)
    pp.pprint(client.downloadChunk(args[0],))

elif cmd == 'getNimbusConf':
    if len(args) != 0:
        print('getNimbusConf requires 0 args')
        sys.exit(1)
    pp.pprint(client.getNimbusConf())

elif cmd == 'getClusterInfo':
    if len(args) != 0:
        print('getClusterInfo requires 0 args')
        sys.exit(1)
    pp.pprint(client.getClusterInfo())

elif cmd == 'getTopologySummaries':
    if len(args) != 0:
        print('getTopologySummaries requires 0 args')
        sys.exit(1)
    pp.pprint(client.getTopologySummaries())

elif cmd == 'getTopologySummaryByName':
    if len(args) != 1:
        print('getTopologySummaryByName requires 1 args')
        sys.exit(1)
    pp.pprint(client.getTopologySummaryByName(args[0],))

elif cmd == 'getTopologySummary':
    if len(args) != 1:
        print('getTopologySummary requires 1 args')
        sys.exit(1)
    pp.pprint(client.getTopologySummary(args[0],))

elif cmd == 'getLeader':
    if len(args) != 0:
        print('getLeader requires 0 args')
        sys.exit(1)
    pp.pprint(client.getLeader())

elif cmd == 'isTopologyNameAllowed':
    if len(args) != 1:
        print('isTopologyNameAllowed requires 1 args')
        sys.exit(1)
    pp.pprint(client.isTopologyNameAllowed(args[0],))

elif cmd == 'getTopologyInfoByName':
    if len(args) != 1:
        print('getTopologyInfoByName requires 1 args')
        sys.exit(1)
    pp.pprint(client.getTopologyInfoByName(args[0],))

elif cmd == 'getTopologyInfo':
    if len(args) != 1:
        print('getTopologyInfo requires 1 args')
        sys.exit(1)
    pp.pprint(client.getTopologyInfo(args[0],))

elif cmd == 'getTopologyInfoByNameWithOpts':
    if len(args) != 2:
        print('getTopologyInfoByNameWithOpts requires 2 args')
        sys.exit(1)
    pp.pprint(client.getTopologyInfoByNameWithOpts(args[0], eval(args[1]),))

elif cmd == 'getTopologyInfoWithOpts':
    if len(args) != 2:
        print('getTopologyInfoWithOpts requires 2 args')
        sys.exit(1)
    pp.pprint(client.getTopologyInfoWithOpts(args[0], eval(args[1]),))

elif cmd == 'getTopologyPageInfo':
    if len(args) != 3:
        print('getTopologyPageInfo requires 3 args')
        sys.exit(1)
    pp.pprint(client.getTopologyPageInfo(args[0], args[1], eval(args[2]),))

elif cmd == 'getSupervisorPageInfo':
    if len(args) != 3:
        print('getSupervisorPageInfo requires 3 args')
        sys.exit(1)
    pp.pprint(client.getSupervisorPageInfo(args[0], args[1], eval(args[2]),))

elif cmd == 'getComponentPageInfo':
    if len(args) != 4:
        print('getComponentPageInfo requires 4 args')
        sys.exit(1)
    pp.pprint(client.getComponentPageInfo(args[0], args[1], args[2], eval(args[3]),))

elif cmd == 'getTopologyConf':
    if len(args) != 1:
        print('getTopologyConf requires 1 args')
        sys.exit(1)
    pp.pprint(client.getTopologyConf(args[0],))

elif cmd == 'getTopology':
    if len(args) != 1:
        print('getTopology requires 1 args')
        sys.exit(1)
    pp.pprint(client.getTopology(args[0],))

elif cmd == 'getUserTopology':
    if len(args) != 1:
        print('getUserTopology requires 1 args')
        sys.exit(1)
    pp.pprint(client.getUserTopology(args[0],))

elif cmd == 'getTopologyHistory':
    if len(args) != 1:
        print('getTopologyHistory requires 1 args')
        sys.exit(1)
    pp.pprint(client.getTopologyHistory(args[0],))

elif cmd == 'getOwnerResourceSummaries':
    if len(args) != 1:
        print('getOwnerResourceSummaries requires 1 args')
        sys.exit(1)
    pp.pprint(client.getOwnerResourceSummaries(args[0],))

elif cmd == 'getSupervisorAssignments':
    if len(args) != 1:
        print('getSupervisorAssignments requires 1 args')
        sys.exit(1)
    pp.pprint(client.getSupervisorAssignments(args[0],))

elif cmd == 'sendSupervisorWorkerHeartbeats':
    if len(args) != 1:
        print('sendSupervisorWorkerHeartbeats requires 1 args')
        sys.exit(1)
    pp.pprint(client.sendSupervisorWorkerHeartbeats(eval(args[0]),))

elif cmd == 'sendSupervisorWorkerHeartbeat':
    if len(args) != 1:
        print('sendSupervisorWorkerHeartbeat requires 1 args')
        sys.exit(1)
    pp.pprint(client.sendSupervisorWorkerHeartbeat(eval(args[0]),))

elif cmd == 'processWorkerMetrics':
    if len(args) != 1:
        print('processWorkerMetrics requires 1 args')
        sys.exit(1)
    pp.pprint(client.processWorkerMetrics(eval(args[0]),))

elif cmd == 'isRemoteBlobExists':
    if len(args) != 1:
        print('isRemoteBlobExists requires 1 args')
        sys.exit(1)
    pp.pprint(client.isRemoteBlobExists(args[0],))

else:
    print('Unrecognized method %s' % cmd)
    sys.exit(1)

transport.close()
